package entity

import (
	"strconv"
)

// GetSidePosSide 获取操作方向
func GetSidePosSide(opType string) (string, string) {
	if opType == LONG {
		return BUY, LONG
	} else {
		return SELL, SHORT
	}
}

// StringToFloat64 将字符串转换为float64
func StringToFloat64(str string) (float64, error) {
	return strconv.ParseFloat(str, 64)
}

// Float64ToString 将float64转换为字符串
func Float64ToString(f float64) string {
	return strconv.FormatFloat(f, 'f', -1, 64)
}

// CalculateTargetPrice 计算止盈价格
func CalculateTargetPrice(opType string, openPrice string, profitTargetPercent float64) string {
	openPriceFloat, _ := StringToFloat64(openPrice)
	var tpPrice float64
	if opType == LONG {
		tpPrice = openPriceFloat * (1 + profitTargetPercent/100)
	} else {
		tpPrice = openPriceFloat * (1 - profitTargetPercent/100)
	}
	return Float64ToString(tpPrice)
}

// CalculateCoverPositionPrice 计算补仓价格
func CalculateCoverPositionPrice(opType string, openPrice string, coverPositionPercent float64) string {
	openPriceFloat, _ := StringToFloat64(openPrice)
	var cpPrice float64
	if opType == LONG {
		cpPrice = openPriceFloat * (1 - coverPositionPercent/100)
	} else {
		cpPrice = openPriceFloat * (1 + coverPositionPercent/100)
	}
	return Float64ToString(cpPrice)
}
